function! CheckBackspace() abort
    let col = col('.') - 1
    return !col || getline('.')[col - 1]  =~# '\s'
endfunction


" Removes trailing spaces
function! TrimWhiteSpace()
    %s/\s\+$//e
endfunction


" MultiCursor is conflicting with deoplete
func! Multiple_cursors_before()
    call deoplete#init#_disable()
endfunc
func! Multiple_cursors_after()
    call deoplete#init#_enable()
endfunc

" Removes trailing spaces
function! TrimWhiteSpace()
    %s/\s\+$//e
endfunction


" MultiCursor is conflicting with deoplete
func! Multiple_cursors_before()
    call deoplete#init#_disable()
endfunc
func! Multiple_cursors_after()
    call deoplete#init#_enable()
endfunc

function! Fzf_dev()
    let l:fzf_files_options = ' -m --bind ctrl-d:preview-page-down,ctrl-u:preview-page-up --preview "bat --color always --style numbers {2..}"'

    function! s:files()
        let l:files = split(system($FZF_DEFAULT_COMMAND), '\n')
        return s:prepend_icon(l:files)
    endfunction

    function! s:prepend_icon(candidates)
        let result = []
        for candidate in a:candidates
            let filename = fnamemodify(candidate, ':p:t')
            let icon = WebDevIconsGetFileTypeSymbol(filename, isdirectory(filename))
            call add(result, printf("%s %s", icon, candidate))
        endfor

        return result
    endfunction

    function! s:edit_file(items)
        let items = a:items
        let i = 1
        let ln = len(items)
        while i < ln
            let item = items[i]
            let parts = split(item, ' ')
            let file_path = get(parts, 1, '')
            let items[i] = file_path
            let i += 1
        endwhile
        call s:Sink(items)
    endfunction

    let opts = fzf#wrap({})
    let opts.source = <sid>files()
    let s:Sink = opts['sink*']
    let opts['sink*'] = function('s:edit_file')
    let opts.options .= l:fzf_files_options
    call fzf#run(opts)

endfunction

" NERDTrees File highlighting
function! NERDTreeHighlightFile(extension, fg, bg, guifg, guibg)
    exec 'autocmd FileType nerdtree highlight ' . a:extension .' ctermbg='. a:bg .' ctermfg='. a:fg .' guibg='. a:guibg .' guifg='. a:guifg
    exec 'autocmd FileType nerdtree syn match ' . a:extension .' #^\s\+.*'. a:extension .'$#'
endfunction




" function! s:myLocalDb()
"     let db = ZFVimIM_dbInit({
"                 \   'name' : 'YourDb',
"                 \ })
"     call ZFVimIM_cloudRegister({
"                 \   'mode' : 'local',
"                 \   'dbId' : db['dbId'],
"                 \   'repoPath' : '/path/to/repo',
"                 \   'dbFile' : '/YourDbFile',
"                 \   'dbCountFile' : '/YourDbCountFile',
"                 \ })
" endfunction
" autocmd User ZFVimIM_event_OnDbInit call s:myLocalDb()
"
